const { app, BrowserWindow, globalShortcut, ipcMain, session } = require('electron')
let path = require("path")

ipcMain.on("save-page", (e, args) => {
    if (!global.page) {
        global.page = {}
    }
    global.page[args.id] = args.data
    e.returnValue = true
})

ipcMain.on("get-page", (e, args) => {
    e.returnValue = global.page[args]
})

function createWindow() {
    // 创建浏览器窗口
    win = new BrowserWindow({
        width: 800, height: 600, webPreferences: {
            preload: path.join(__dirname, 'preload/main_sdk.js')
        }
    })

    win.loadFile(path.join(__dirname, 'web/index.html'))
    win.webContents.openDevTools()
    win.maximize()


    globalShortcut.register('CommandOrControl+Alt+I', function () {
        win.webContents.openDevTools()
    })

    app.on('window-all-closed', () => {
        app.quit()
    })
}

app.on('ready', createWindow)